package com.zhitan.ems.framework.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;

@Configuration
@EnableKnife4j
public class Knife4jOpenApiConfig {

    @Value("${spring.application.name:能源管理系统}")
    private String serviceName;

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(serviceName + "API文档")
                .description("能源管理系统API接口文档")
                .version("1.0")
                .contact(new Contact("智坦科技", "https://www.zhitan.vip", "support@zhitan.vip"))
                .build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .groupName("能源管理系统")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();

        return docket;
    }
}